package com.flame.system.log.config;

import java.util.List;

import javax.annotation.PostConstruct;

import com.flame.system.log.interceptor.OperatorLogInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * SystemLogConfiguration
 *
 * @author wuxintong
 * @since 2023/2/23
 */
@EnableAsync
@MapperScan("com.flame.system.log.mapper")
@ComponentScan("com.flame.system.log")
@Configuration
@EnableConfigurationProperties(SystemLogConfigurationProperties.class)
public class SystemLogConfiguration implements WebMvcConfigurer {

    @Autowired
    private SystemLogConfigurationProperties properties;

    @Autowired
    private ApplicationEventPublisher publisher;

    @PostConstruct
    public void init() {
        List<String> excludeUrl = properties.getExcludeUrl();
        excludeUrl.add("/system/log/**");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new OperatorLogInterceptor(publisher, properties)).order(5).addPathPatterns("/**");
    }
}
